home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / DJ111M3.ZIP / lib / crt0.s < prev    next >
Text File  |  1994-02-09  |  5KB  |  250 lines

  1.  
  2. /*
  3. **    Called as start(argc, argv, envp)
  4. */
  5.  
  6. /*    gs:edx points to prog_info structure.  All other registers are OBSOLETE
  7. **    but included for backwards compatibility
  8. */
  9.  
  10. /* These symbols are for global constructors and destructors */
  11.     .section    .ctor
  12.     .globl        ___go32_first_ctor
  13. ___go32_first_ctor:
  14.     .section    .dtor
  15.     .globl        ___go32_last_ctor
  16. ___go32_last_ctor:
  17.     .globl        ___go32_first_dtor
  18. ___go32_first_dtor:
  19.     .data
  20.     .globl        ___go32_last_dtor
  21. ___go32_last_dtor:
  22.  
  23.     .text
  24.     .globl    _start
  25. _start:
  26.     .globl    start
  27. start:
  28. #ifdef EMU387
  29.     pusha
  30.     push    %gs
  31. #endif
  32.     movl    %eax,__hard_master
  33.     movl    %esi,___pid
  34.     movl    %edi,___transfer_buffer
  35.     movl    %ebx,_ScreenPrimary
  36.     movl    %ebp,_ScreenSecondary
  37.  
  38.     cmpl    $0, %edx
  39.     je    Lcopy_none
  40.     movw    %gs,%cx
  41.     movw    %ds,%ax
  42.     cmpw    %cx,%ax
  43.     je    Lcopy_none
  44.  
  45.     movl    %gs:(%edx), %ecx
  46.     cmpl    __go32_info_block, %ecx
  47.     jbe    Lcopy_less
  48.     movl    __go32_info_block, %ecx
  49. Lcopy_less:
  50.     movl    $__go32_info_block, %edi
  51.     addl    $3, %ecx
  52.     andl    $0xfffffffc, %ecx
  53.     movl    %ecx, (%edi)
  54.     addl    $4, %edi
  55.     addl    $4, %edx
  56.     subl    $4, %ecx
  57. Lcopy_more:
  58.     movl    %gs:(%edx), %eax
  59.     movl    %eax, (%edi)
  60.     addl    $4, %edx
  61.     addl    $4, %edi
  62.     subl    $4, %ecx
  63.     jnz    Lcopy_more
  64.  
  65.     movl    __go32_info_block+4, %eax
  66.     movl    %eax, _ScreenPrimary
  67.     movl    __go32_info_block+8, %eax
  68.     movl    %eax, _ScreenSecondary
  69. /* Backward compatibility - do not copy this one!
  70. **    movl    __go32_info_block+12, %eax
  71. **    movl    %eax, ___transfer_buffer
  72. */
  73.     movl    __go32_info_block+20, %eax
  74.     movl    %eax, ___pid
  75.     movl    __go32_info_block+24, %eax
  76.     movl    %eax, __hard_master
  77.  
  78.     jmp    Lcopy_done
  79.  
  80. Lcopy_none:
  81.     movl    %ebx,__go32_info_block+4
  82.     movl    %ebp,__go32_info_block+8
  83.     movl    %edi,__go32_info_block+12
  84.     movl    $4096,__go32_info_block+16
  85.     movl    %esi,__go32_info_block+20
  86.     movl    %eax,__go32_info_block+24
  87.     movl    $28, __go32_info_block
  88. Lcopy_done:
  89.  
  90. #ifndef EMU387
  91.     call    __setstack
  92. #endif
  93.     xorl    %esi,%esi
  94.     xorl    %edi,%edi
  95.     xorl    %ebp,%ebp
  96.     xorl    %ebx,%ebx
  97.  
  98.     movl    %esp,%ebx
  99. #ifdef MAKE_GCRT0
  100.     call    mcount_init /* initialize the profiler */
  101. #endif
  102.     movl    8(%ebx),%eax
  103.     pushl    %eax
  104.     movl    %eax,_environ
  105.     pushl    4(%ebx)
  106.     pushl    (%ebx)
  107.     call    ___main
  108.     call    _main
  109.     addl    $12,%esp
  110. #ifdef EMU387
  111.     pop    %gs
  112.     popa
  113. #else
  114.     pushl    %eax
  115.     call    _exit
  116.  
  117. exit_again:
  118.     movl    $0x4c00,%eax
  119.     int    $0x21
  120.     jmp    exit_again
  121. #endif
  122.  
  123.     ret
  124.  
  125.  
  126. #ifdef MAKE_GCRT0
  127.     .globl    __exit
  128. __exit:
  129.     call    mcount_write /* make sure we dump the output */
  130. exit_again2:
  131.     movb    4(%esp),%al
  132.     movb    $0x4c,%ah
  133.     int    $0x21
  134.     jmp    exit_again2
  135.  
  136. mcount_ds:
  137.     .word    0
  138. mcount_max:
  139.     .long    0
  140.  
  141. /* Here is where we initialize the timer interrupt - specific to go32 */
  142. /* In this case, the timer calls mcount_isr */
  143.     .globl    mcount_isr_init
  144. mcount_isr_init:
  145.     movw    __go32_info_block+36, %ax    /* run mode */
  146.     cmpw    $1,%ax
  147.     jb    skip_mcount
  148.     cmpw    $3,%ax
  149.     ja    skip_mcount
  150.  
  151.     movw    %ds,%ax
  152.     movw    %ax,mcount_ds
  153.     movl    $_end,%eax
  154.     subl    $0x1020,%eax
  155.     movl    %eax,mcount_max
  156.     movw    $16,%ax
  157.     movw    %ax,%gs
  158.  
  159.     movzbl    __hard_master,%eax    /* timer is on irq 0 */
  160.     shll    $3,%eax /* times 8 bpv */
  161. /*    movl    $960,%eax       vector 0x78 * 8 bpv */
  162.     movw    %gs:(%eax),%cx
  163.     movw    %cx,mc_chain
  164.     movw    %gs:6(%eax),%cx
  165.     movw    %cx,mc_chain_hi
  166.     movw    %gs:2(%eax),%cx
  167.     movw    %cx,mc_chain_sel
  168.  
  169.     movl    $mcount_isr,%ecx
  170.     movw    %cx,%gs:(%eax)
  171.     movw    $0xd8,%gs:2(%eax)    /* selector 27 == 32-bit code */
  172.     movw    $0x8f00,%gs:4(%eax)
  173.     rorl    $16,%ecx
  174.     movw    %cx,%gs:6(%eax)
  175.     movw    %ds,%ax
  176.     movw    %ax,%gs
  177. skip_mcount:
  178.     movl    mcount_histogram,%eax
  179.     movl    $1,(%eax)
  180.     ret
  181.  
  182. /* Obtain the PC where we interrupted, and bump the histogram.  We should  */
  183. /* do error checking here, but we don't.  This routine is specific to go32 */
  184. /* in some spots */
  185. mcount_isr:
  186.     pushl    %eax
  187.     movw    %ds,%ax
  188.     pushl    %eax
  189.     .byte 0x2e /* CS: */
  190.     movw    mcount_ds,%ax
  191.     movw    %ax,%ds
  192.     cmpl    $1,mcount_skip
  193.     je    L0
  194.     movl    8(%esp),%eax /* get the PC */
  195.     subl    $0x1020,%eax /* to fit in low..high */
  196.     cmpl    mcount_max,%eax
  197.     jae    L0
  198.     andl    $0xfffffffc,%eax
  199.     shrl    $1,%eax /* now points to one 2-byte entry */
  200.     addl    mcount_histogram,%eax
  201.     incw    (%eax)
  202. L0:
  203.     popl    %eax
  204.     movw    %ax,%ds
  205.     popl    %eax
  206.     ljmp    mc_chain /* chain to the next timer vector */
  207.     iret
  208. #endif
  209.  
  210.     .data
  211.  
  212.     .globl    _environ
  213. _environ:
  214.     .long    0
  215.  
  216.     .globl    ___pid
  217. ___pid:
  218.     .long    42
  219.  
  220.     .globl    ___transfer_buffer
  221. ___transfer_buffer:
  222.     .long    0
  223.  
  224.     .globl    _ScreenPrimary
  225. _ScreenPrimary:
  226.     .long    0
  227.  
  228.     .globl    _ScreenSecondary
  229. _ScreenSecondary:
  230.     .long    0
  231.  
  232.     .globl    __hard_master
  233.     .globl    __hard_slave
  234.     .globl    __core_select
  235. __hard_master:
  236.     .byte    0
  237. __hard_slave:
  238.     .byte    0
  239. __core_select:
  240.     .short    0
  241.  
  242. #ifdef MAKE_GCRT0
  243. mc_chain:
  244.     .short    0
  245. mc_chain_hi:
  246.     .short    0
  247. mc_chain_sel:
  248.     .short    0
  249. #endif
  250.